package com.neuedu.his.service;



import com.neuedu.his.common.Page;
import com.neuedu.his.common.utils.ParamUtils;
import com.neuedu.his.dao.UmsRoleDao;
import com.neuedu.his.entity.UmsRole;
import com.neuedu.his.common.core.BaseService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;



public class UmsRoleService implements BaseService<UmsRole>   {

    private UmsRoleDao dao = new UmsRoleDao();


    public Page queryList(HttpServletRequest request){
        int pageNo = 1;
        int size = 10;

        String paramPageNo = request.getParameter("pageNo");
        String paraSize = request.getParameter("size");

        if(!Objects.isNull(paramPageNo)){
            pageNo = Integer.parseInt(paramPageNo);
        }
        if(!Objects.isNull(paraSize)){
            size = Integer.parseInt(paraSize);
        }

        List paraList = new ArrayList();
        String where  = "where 1=1   ";

        Object[] params = paraList.toArray();
        long total  = dao.selectCount(where,params);
        List<UmsRole> data = dao.selectPage(where,pageNo,size,params);

        return  Page.getInstatnce(pageNo ,size , data , total);
    }


    public boolean save(HttpServletRequest req) {
        UmsRole  umsRole   =  ParamUtils.getParam(UmsRole.class,req);
        return  dao.insert(umsRole) >0;
    }

    public boolean update(HttpServletRequest req) {
        UmsRole  umsRole   =  ParamUtils.getParam(UmsRole.class,req);
        return  dao.updateById( umsRole ) >0;
    }


    public  UmsRole queryById(HttpServletRequest req) {
        String roleId = req.getParameter("roleId");
        String where = " where role_id = ?";
        Object params[] = {roleId};
        return dao.selectOne(where,params);
    }


    /**
    * 根据主键删除
    * @param req
    * @return
    */
    public boolean deleteById(HttpServletRequest req) {
        String roleId = req.getParameter("roleId");
        return dao.deleteById(Integer.parseInt(roleId))>0;
    }
}
